package com.bestv.search.common.dao.hibernate;

import com.bestv.search.common.dao.ChannelDao;
import com.bestv.search.common.model.Channel;

import java.util.List;

/**
 * @author Michael Wang
 */
public class ChannelDaoHibernate extends GenericDaoHibernate<Channel, Long> implements ChannelDao {

    @SuppressWarnings("unchecked")
    public Channel getChannelByName(String name) {
        List<Channel> channels = getHibernateTemplate().find("from Channel c where c.name = ?", name);
        if (channels == null || channels.size() == 0)
            return null;
        return channels.get(0);
    }

    @SuppressWarnings("unchecked")
    public Channel getChannelByCode(String code) {
        List<Channel> channels = getHibernateTemplate().find("from Channel c where c.code = ?", code);
        if (channels == null || channels.size() == 0)
            return null;
        return channels.get(0);
    }
}
